// https://www.lintcode.com/problem/rotate-string/my-submissions?_from=ladder&&fromId=6

class Solution {
public:
    /**
     * @param str: An array of char
     * @param offset: An integer
     * @return: nothing
     */
    void rotateString(string &str, int offset) {
        // if (str.empty()) return;
        // int l = str.length();
        // offset = offset % l;
        // str = str.substr(l - offset, offset) + str.substr(0, l - offset);
        
        //法二：
        if (str.empty()) return;
        offset = offset % str.length(); //重要
        reverse(str.begin(), str.end());
        reverse(str.begin(), str.begin() + offset);
        reverse(str.begin() + offset, str.end());
    }
};